package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.common.ServerResponse;
import com.situ.mall.dao.CategoryMapper;
import com.situ.mall.entity.Category;
import com.situ.mall.entity.CategoryCount;
import com.situ.mall.service.ICategoryService;

@Service
public class CategoryServiceImpl implements ICategoryService{
	@Autowired
	private CategoryMapper categoryMapper;

	@Override
	public ServerResponse pageList(Integer page, Integer limit, Category category) {
		PageHelper.startPage(page, limit);
		
//		CategoryExample categoryExmple = new CategoryExample();
//		Criteria criteria = categoryExmple.createCriteria();
//		if(category.getId() != null) {
//			criteria.andIdEqualTo(category.getId());
//		}
//		
//		if(category.getName() != null && !"".equals(category.getName())) {
//			criteria.andNameLike("%" + category.getName() + "%");
//		}
		
//		List<Category> list = categoryMapper.selectByExample(categoryExmple);
		List<Category> list = categoryMapper.pageList(category);
		PageInfo pageInfo = new PageInfo(list);
		int count = (int) pageInfo.getTotal();
		return ServerResponse.createSuccess("", count, list);
	}

	@Override
	public ServerResponse selectTopCategory() {
		List<Category> list = categoryMapper.selectTopCategory();
		return ServerResponse.createSuccess("", list);
	}
	
	@Override
	public ServerResponse selectSecondCategory(Integer topCategoryId) {
		List<Category> list = categoryMapper.selectSecondCategory(topCategoryId);
		return ServerResponse.createSuccess("", list);
	}

	@Override
	public ServerResponse getCategoryProductCount() {
		List<CategoryCount>list = categoryMapper.getCategoryProductCount();
		return ServerResponse.createSuccess("", list);
	}

	@Override
	public List<Category> selectTopCategoryList() {

		return categoryMapper.selectTopCategory();
	}

	@Override
	public List<Category> selectSecondCategoryList() {
		return categoryMapper.selectSecondCategoryList();
	}
}
